package com.colt.usercenter.controller.user;

import com.colt.usercenter.domain.dto.message.UserUpdateBonusMsgDTO;
import com.colt.usercenter.domain.entity.user.User;
import com.colt.usercenter.service.user.impl.UserServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: spring-cloud-alibaba-we-chat-app
 * @description:
 * @author: colt
 * @create: 2020-11-04 16:31
 **/
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BonusController {
    private final UserServiceImpl userService;
    @PutMapping("/add-bonus")
    public User addBonus(@RequestBody UserUpdateBonusMsgDTO dto){
        Integer userId = dto.getUserId();
        userService.addBonus(UserUpdateBonusMsgDTO.builder()
                .bonus(dto.getBonus())
                .userId(userId)
                .description("积分购买分享")
                .event("BUY")
                .build());
        return this.userService.findById(userId);
    }
}
